package com.sml.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author linlx
 * @Date 2021/9/7 16:31
 * @Description
 **/
public class DateUtil {

  private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

  // 本地日期格式
  private static final ThreadLocal<DateFormat> LOCAL_DATE_FORMAT = ThreadLocal
      .withInitial(() -> new SimpleDateFormat(DATE_FORMAT));

  // 格式化日期函数
  public static String getFormatDate(Date date) {
    return LOCAL_DATE_FORMAT.get().format(date);
  }


  private static final String REQUEST_DATE_FORMAT = "yyyyMMddHHmmss";

  // 本地日期格式
  private static final ThreadLocal<DateFormat> LOCAL_REQUEST_DATE_FORMAT = ThreadLocal
      .withInitial(() -> new SimpleDateFormat(REQUEST_DATE_FORMAT));

  // 格式化日期函数
  public static String getRequestDateFormat(Date date) {
    return LOCAL_REQUEST_DATE_FORMAT.get().format(date);
  }


}
